var util = {
    hasClass:  function(ele, cls) {
        return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
    },

    addClass: function (ele, cls) {
        if (!this.hasClass(ele, cls)) ele.className += " " + cls;
    },

    removeClass: function (ele, cls) {
        if (hasClass(ele, cls)) {
            var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
            ele.className = ele.className.replace(reg, ' ');
        }
    },

    replaceClass: function (ele, oldClass, newClass){
        if(hasClass(ele, oldClass)){
            removeClass(ele, oldClass);
            addClass(ele, newClass);
        }
        return;
    },

    toggleClass: function (ele, cls1, cls2){
        if(hasClass(ele, cls1)){
            replaceClass(ele, cls1, cls2);
        }else if(hasClass(ele, cls2)){
            replaceClass(ele, cls2, cls1);
        }else{
            addClass(ele, cls1);
        }
    }
}